#ifndef AJAX_H
#define AJAX_H

#include <QObject>
#include <QtNetwork>
// #include <QDeclarativeView>
// #include <QDeclarativeContext>
// #include <QDeclarativeItem>
#include "cookiejar.h"
#include "inflatestream.h"

class Ajax : public QObject
{
    Q_OBJECT
public:
  explicit Ajax(QObject *parent = 0);
  virtual ~Ajax();
  Q_INVOKABLE QNetworkReply *post(const QString &url, const QMap<QString, QString> &headers, const QString &param);
  Q_INVOKABLE QNetworkReply *post(const QString &url, const QMap<QString, QString> &headers, bool compress);
  Q_INVOKABLE QNetworkReply *get(const QString &url, const QMap<QString, QString> &headers, bool compress);
  Q_INVOKABLE void post(const QString &url, const QString &param, bool compress);
  Q_INVOKABLE void get(const QString &url, bool compress);

signals:
  void success(int status, const QString &value);
  void error(int status, const QString &value);

public slots:
  void nmfinished();
  void nmerror(QNetworkReply::NetworkError code);
//  void requestFinished(int id, bool error);

private:
  QNetworkAccessManager nam;
  QNetworkRequest       request;
  CookieJar             *cookie;
};

#endif // AJAX_H
